import 'terms.dart';

/// 方向集合
const directions = [
  [-1, -1], // 0左上
  [-2, 0], // 1上2
  [-1, 1], // 2右上
  [1, -1], // 3左下
  [0, -2], // 4左2
  [2, 0], // 5下2
  [1, 1], // 6右下
  [0, 2], // 7右2
  [0, -1], // 8左1
  [0, 1], // 9右1
  [1, 0], // 10下1
  [-1, 0] // 11上1
];

/// 抽象术语方位
enum AbstractDirection {
  // 抽象中腹
  middle,
  // 抽象边角
  specialSideCornerLeft,
  specialSideCornerBottom,
  specialSideCornerRight,
  specialSideCornerTop,
  // 抽象特殊点
  specialDot;

  const AbstractDirection();
}

/// 抽象术语⽅位
/// ChessStep的x是从上往下的方向、y是从左往右的方向
AbstractDirection judgeFromAbstractDirection(Board board, ChessStep? nextStep) {
  // printInfo("x:${nextStep!.x},y:${nextStep.y}");
  int boardSize = board.getBoardSize();
  int x = nextStep!.y;
  int y = boardSize + 1 - nextStep.x;
  // printInfo("x:$x,y:$y");

  int boardLimit = boardSize == 9 ? 3 : 4;

  if ((y > boardSize - boardLimit && y < boardSize + 1) &&
      (x >= boardSize + 1 - y && x <= y)) {
    if (x == boardSize + 1 - y || x == y) {
      return AbstractDirection.specialDot;
    } else {
      return AbstractDirection.specialSideCornerTop;
    }
  } else if ((y > 0 && y < boardLimit + 1) &&
      (x >= y && x <= boardSize + 1 - y)) {
    if (x == y || x == boardSize + 1 - y) {
      return AbstractDirection.specialDot;
    } else {
      return AbstractDirection.specialSideCornerBottom;
    }
  } else if ((x > 0 && x < boardLimit + 1) &&
      (y >= x && y <= boardSize + 1 - x)) {
    if (y == x || y == boardSize + 1 - x) {
      return AbstractDirection.specialDot;
    } else {
      return AbstractDirection.specialSideCornerLeft;
    }
  } else if ((x > boardSize - boardLimit && x < boardSize + 1) &&
      (y >= boardSize + 1 - x && y <= x)) {
    if (y == boardSize + 1 - x || y == x) {
      return AbstractDirection.specialDot;
    } else {
      return AbstractDirection.specialSideCornerRight;
    }
  }

  return AbstractDirection.middle;
}
